package com.viknix.threadpool.manager.client.global;

import com.viknix.threadpool.manager.client.core.DynamicThreadPoolWrap;
import com.viknix.threadpool.manager.common.model.PoolParameterInfo;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: Dongqi
 * @Date: 2021/10/23 15:42
 * @Version 1.0
 * @Description: 全局管理器
 */
public class GlobalThreadPoolManage {

    private static final Map<String, PoolParameterInfo> POOL_PARAMETER = new ConcurrentHashMap();

    private static final Map<String, DynamicThreadPoolWrap> EXECUTOR_MAP = new ConcurrentHashMap();

    public static DynamicThreadPoolWrap getExecutorService(String threadPoolId) {
        return EXECUTOR_MAP.get(threadPoolId);
    }

    public static PoolParameterInfo getPoolParameter(String threadPoolId) {
        return POOL_PARAMETER.get(threadPoolId);
    }

    public static void register(String threadPoolId, PoolParameterInfo poolParameter, DynamicThreadPoolWrap wrap) {
        registerPool(threadPoolId, wrap);
        registerPoolParameter(threadPoolId, poolParameter);
    }

    public static void registerPool(String threadPoolId, DynamicThreadPoolWrap executor) {
        EXECUTOR_MAP.put(threadPoolId, executor);
    }

    public static void registerPoolParameter(String threadPoolId, PoolParameterInfo poolParameter) {
        POOL_PARAMETER.put(threadPoolId, poolParameter);
    }

}
